模拟实现一个 Promise.finally
2020/02/03
Promise.prototype.finally = function (cb) {
let P = this.constructor;
return this.then(
value => P.resolve(cb()).then(() => value),
reason => P.resolve(cb()).then(() => { throw reason })
);
};
charleyup
为自己吹过的🐮🍺奋斗终生.
2020/02/03
Promise.prototype.finally = function (cb) {
let P = this.constructor;
return this.then(
value => P.resolve(cb()).then(() => value),
reason => P.resolve(cb()).then(() => { throw reason })
);
};